package cn.lijiajia3515.cairo.auth.modules;

import cn.lijiajia3515.cairo.auth.framework.security.oauth2.CairoOAuth2User;
import cn.lijiajia3515.cairo.core.CoreConstants;
import cn.lijiajia3515.cairo.domain.CairoRole;
import lombok.Data;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.security.PermitAll;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.MonthDay;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.Date;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@RestController
@RequestMapping("/api/test")
public class TestApi {
	private final RedisTemplate<String, Object> redisTemplate;

	public TestApi(RedisTemplate<String, Object> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}

	@GetMapping("/1")
	@PermitAll
	public AllType a1() {
		String key = "test:" + CoreConstants.SNOWFLAKE.nextIdStr();
		AllType allType = new AllType();
		redisTemplate.opsForValue().set(key, allType);
		return (AllType) redisTemplate.opsForValue().get(key);

	}

	@Data
	public static  class AllType {
		private Boolean fBoolean = false;
		private Integer integer = Integer.MAX_VALUE;
		private Short fShort = Short.MAX_VALUE;
		private Double aDouble1 = Double.MAX_VALUE;
		private Long long1 = Long.MAX_VALUE;
		private BigDecimal bigDecimal = BigDecimal.TEN;

		private String string = "1234";
		private Date date = new Date();

		private LocalDate localDate = LocalDate.now();
		private LocalTime localTime = LocalTime.now();
		private LocalDateTime localDateTime = LocalDateTime.now();
		private OffsetDateTime offsetDateTime = OffsetDateTime.now();

		private ZoneId zoneId = ZoneId.systemDefault();
		private ZoneOffset zoneOffset = ZoneOffset.MAX;
		private ZonedDateTime zonedDateTime = ZonedDateTime.now();

		private Duration duration = Duration.ofDays(1);
		private MonthDay monthDay = MonthDay.of(1, 1);
		private OffsetTime offsetTime = OffsetTime.now();
		private Period period = Period.of(1, 1, 1);

		private GrantedAuthority authority = new SimpleGrantedAuthority("111");

		private CairoOAuth2User cairoOAuth2User = CairoOAuth2User.builder()
			.id("1")
			.roles(Collections.singletonList(CairoRole.builder().id("1").name("1").build()))
			.authorities(Stream.of("1", "2").map(SimpleGrantedAuthority::new).collect(Collectors.toList()))
			.build();


	}

}
